<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="__ROOT__/static/admin/css/pintuer.css">
    <link rel="stylesheet" href="__ROOT__/static/admin/css/admin.css">
    <script src="__ROOT__/static/plugins/jquery-3.2.1/jquery-3.2.1.js"></script>
    <script src="__ROOT__/static/admin/js/pintuer.js"></script>
    <script src="__ROOT__/static/plugins/layer/layer.min.js"></script>
</head>
<body>
<form method="post" action="">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 话题贴列表</strong></div>
        <div class="padding border-bottom">
            <ul class="search">
                <li>
                    <button type="button"  class="button border-green" id="checkall"><span class="icon-check"></span> 全选</button>
                    <a  class="button border-red" onclick="DelSelect()"><span class="icon-trash-o"></span> 批量删除</a>
                </li>
            </ul>
        </div>
        <table class="table table-hover text-center">
            <tr>
                <th>ID</th>
                <th>话题名称</th>
                <th width="800">话题内容</th>
                <th width="120">发布时间</th>
                <th>评论</th>
                <th>点赞</th>
                <th>操作</th>
            </tr>
            {volist name="res" id="vo" key="i"}
            <tr>
                <td>
                    <input type="checkbox" class="checkid" name="id" value="{$vo.id}" />
                </td>
                <td>{$vo.title}</td>
                <td>{$vo.topic_content}</td>
                <td>{:date('Y-m-d H:i:s',$vo.report_time)}</td>
                <td>1</td>
                <td>2</td>
                <td>
                    <a class="button border-red" href="javascript:;" onclick="del({$vo.id})"><span class="icon-trash-o"></span> 删除</a>
                </td>
            </tr>
            {/volist}

            <tr>
                <td colspan="8">
                    <div class="pagelist">
                        {$page}
                    </div>
                </td>
            </tr>
        </table>
    </div>
</form>
<script type="text/javascript">
    /*
     *单个删除
     */
    function del(id){
        var topics = {};
        topics.id = id;
        layer.confirm('您确定要删除吗?', {
            btn: ['确定','取消']
        },  function(){
            $.post("{:url('admin/Topics/delTopics')}", topics, function (response){
                if(response > 0){
                    layer.msg('删除成功', {icon: 5});
                    window.location.href = "{:url('admin/Topics/index')}";
                }else {
                    layer.msg('删除失败', {icon: 5});
                }

            });
        });

    }

    //全选
    $("#checkall").click(function(){
        $("input[name='id']").each(function(){
            if (this.checked) {
                this.checked = false;
            }
            else {
                this.checked = true;
            }
        });
    })

    //批量删除
    function DelSelect(){

        var obj = $('input[class="checkid"]:checked');
        var html=[];
        $(obj).each(function(){
            html.push($(this).val()) ;
        });
        var html2 = html.join(',');
        var parmas={};
        parmas.ids=html2;
        layer.confirm('您确定要删除吗?', {
            btn: ['确定','取消']
        },  function() {
            $.post("{:url('admin/Topics/disCard')}", parmas, function (response) {
                if (response[0] == 1) {
                    layer.msg('删除成功', {icon: 5});
                    window.location.href = "{:url('admin/Topics/index')}";
                } else {
                    layer.msg('删除失败', {icon: 5});
                }
            });
        });
    }
</script>
</body></html>